package sources;

import java.io.IOException;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

import net.rim.device.api.amms.control.fmradio.FmTunerControl;

public class FmRadioStrengthSource extends RandomSource {

	/*private Player p = null;
	private FmTunerControl ftc = null;
	private int lastDb = 0;
	private long timeSet = 0;
	private int nextBytes = 0;
	private int nextBytePosition = 0;*/
	
	public String getSourceName() {
		return "Radio Strength Source";
	}

	protected void generateNext() {
		/*int db = ftc.getDefaultMinSignalStrengthInDb();
		if(lastDb == 0){
			lastDb = db;
			timeSet = System.currentTimeMillis();
		} else if (db != lastDb){
			long current = System.currentTimeMillis();
			byte diff = (byte)(current - timeSet);
			lastDb = db;
			timeSet = current;
			store(diff);
		}*/
	}

	private void store(byte diff) {
		/*nextBytes = nextBytes | (diff << (8 * nextBytePosition));
		nextBytePosition++;
		if(nextBytePosition==4){
			nextBytePosition = 0;
			addToPools(nextBytes);
			addRawData(nextBytes);
			nextBytes = 0;
		}*/
	}

	protected void openResources() {
		/*try {
			p = Manager.createPlayer("capture://radio");
			p.realize();
			ftc = (FmTunerControl) p.getControl(FmTunerControl.class.getName());
			p.prefetch();
			ftc.setFrequency(92100, ftc.getDefaultMinSignalStrengthInDb());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MediaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}

	protected void closeResources() {
		//p.close();
	}

}
